/**
 * Created by feng on 2016/12/21.
 */
//$("#header_user_level").css('left', (document.documentElement.clientWidth - 720) / 2 + 'px');
//var site_url = 'http://localhost/svn/lyw/index.php/';
var site_url = 'http://www.yizhiwang.wang/';
//var site_url = 'http://test.yizhiwang.wang/';

function getHeaderUserJson() {
	$.ajax({
		url: site_url + 'admin/getHeaderUserJson',
		type: 'post',
		data: {},
		dataType: 'json',
		success: function(data) {
			if(data) {

				$('#hu_percent2').css('width', '100%')
				$("#hu_percent1").css('width', '100%')
				$('#header_user_level').show();
				setTimeout(function() {
					$('#hu_level').text(data['user']['level']);
					$('#hu_level1').text(data['user']['level']);

					$('#hu_percent2').css('width', (data['user']['jingyan'] / data['level_arr']['next'][0]) * 100 + '%');
					$('#hu_jingyan').text(data['user']['jingyan'] + '/' + data['level_arr']['next'][0]);

					if(data['can_time'] != 0) {
						headerDaoShu(data['can_time']);
					} else {
						$("#hu_percent1").css('width', '0%')
					}
				}, 300)

			}
		}
	});
}
getHeaderUserJson();
var header_daoshu_time = 0;
var header_jishiqi;

function headerDaoShu(time) {
	if(time < 0) {
		return false;
	}
	header_daoshu_time = time;
	header_jishiqi = setInterval(headerBuildTime, 1000);
}

function headerBuildTime() {
	var hour = parseInt(header_daoshu_time / 60 / 60);
	var min = parseInt((header_daoshu_time - hour * 60 * 60) / 60);
	var sec = header_daoshu_time - hour * 60 * 60 - min * 60;
	if(header_daoshu_time <= 0) {
		clearInterval(header_jishiqi);
		$.ajax({
			url: site_url + 'admin/translationOverDueCheck',
			type: 'post',
			data: {},
			dataType: 'json',
			success: function(data) {
				console.log(data);
				setTimeout(function() {
					window.location.reload();
				}, 300)

			}
		});
		alert('翻译时间已到,系统已经自动提交翻译!请直接关闭该页面');
	}
	var html = hour + ':' + min + ':' + sec;
	$("#hu_daojishi").text(html);

	$("#hu_percent1").css('width', (header_daoshu_time) / (60 * 60 * 24) * 100 + '%');
	header_daoshu_time -= 1;
}